package com.example.team6.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.team6.entity.*;
import com.example.team6.mapper.ChapterMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import com.example.team6.entity.Chapter;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author team6
 * @since 2020-07-01
 */
@RestController
//@RequestMapping("/team6/chapter")
@CrossOrigin
public class ChapterController {

    @Autowired
    ChapterMapper chapterMapper;

    @PostMapping(value = "api/getchapter")
    @ResponseBody
    public List<Chapter> getchapter (@RequestBody Chapter requestUser){

        Map<String, Object> map = new HashMap<String, Object>();
        map.put("courseid",requestUser.getCourseid());
        List<Chapter> chapterList = chapterMapper.selectByMap(map);

        return chapterList;
    }

    @PostMapping(value = "api/setchap")
    @ResponseBody
    public void setchap (@RequestBody Chapter requestUser){

        Chapter chapter = new Chapter();
        chapter.setChaptername(requestUser.getChaptername());
        chapter.setCourseid(requestUser.getCourseid());

        Integer chapterList = chapterMapper.insert(chapter);

    }

    @PostMapping(value = "api/delchap")
    @ResponseBody
    public resultt delchap (@RequestBody Chapter requestUser) {

        System.out.println("1");
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("chapterid", requestUser.getChapterid());
        Integer result = chapterMapper.deleteByMap(map);
        if (null == result) {
            String massage = "账号密码错误";
            return new resultt(400);
        } else {
            System.out.println("test");
            return new resultt(200);
        }
    }


    @PostMapping(value = "api/updatevideo")
    @ResponseBody
    public void updatevideo (@RequestBody Chapter requestUser){

        Chapter chapter = new Chapter();
       // chapter.setChaptername(requestUser.getChaptername());
        chapter.setUrl(requestUser.getUrl());
        chapter.setChapterid(requestUser.getChapterid());

        chapterMapper.updateById(chapter);
        System.out.println("url");
    }

    @PostMapping(value = "api/getvideo")
    @ResponseBody
    public List<Chapter> getvideo (@RequestBody Chapter requestUser) {
        Map<String, Object> map = new HashMap<String, Object>();

        map.put("chapterid", requestUser.getChapterid());
        List<Chapter> scList = chapterMapper.selectByMap(map);
        System.out.println("111111");
        return scList;
    }
}

